package pers.vic.practice.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import pers.vic.boot.base.handler.thymeleaf.XssStringFormatter;
import pers.vic.boot.base.handler.thymeleaf.util.ConversionDialect;
import pers.vic.practice.config.thymeleaf.AuthorityElementTagProcessor;
import pers.vic.practice.config.thymeleaf.CustomerVicDialect;
import pers.vic.practice.config.thymeleaf.DictElementTagProcessor;
import pers.vic.practice.config.thymeleaf.EnumElementTagProcessor;

/**
 * 描述:Thymeleaf Config
 * @author Vic.xu
 * @date 2022-04-12 17:02
 */
@Configuration
public class ThymeleafConfig {

    /**
     * 1. 枚举下拉框
     * 2. 权限控制
     * 3. 字典值
     *
     */
    @Bean
    public CustomerVicDialect customerVicDialect(){
        CustomerVicDialect dialect = new CustomerVicDialect();
        dialect.addProcessor(new EnumElementTagProcessor(CustomerVicDialect.PREFIX));
        dialect.addProcessor(new AuthorityElementTagProcessor(CustomerVicDialect.PREFIX));
        dialect.addProcessor(new DictElementTagProcessor(CustomerVicDialect.PREFIX));

        return dialect;
    }

    /**
     * xss 双括号转义
     *
     */
    @Bean
    public XssStringFormatter xssStringFormatter(){
        return new XssStringFormatter();
    }

    /**
     * 页面数据转换工具类 ${#conversion.convert('xx','type','')}
     */
    @Bean
    public ConversionDialect conversionDialect(){
        return  new ConversionDialect();
    }

}
